library(rstan)
library(survival)
library(tidyverse)
library(tidybayes)
Stan_exponential_survival_model <- "
data{
  int <lower=1> N_uncensored;
  int <lower=1> N_censored;
  int <lower=0> numCovariates;
  matrix[N_censored, numCovariates] X_censored;
  matrix[N_uncensored, numCovariates] X_uncensored;
  vector <lower=0>[N_censored] times_censored;
  vector <lower=0>[N_uncensored] times_uncensored;
}

parameters{
  vector[numCovariates] beta; //regression coefficients
  real alpha; //intercept
}

model{
  beta ~ normal(0,10); //prior on regression coefficients
  alpha ~ normal(0,10); //prior on intercept
  target += exponential_lpdf(times_uncensored | exp(alpha+X_uncensored * beta)); //log-likelihood part for uncensored times
  target += exponential_lccdf(times_censored | exp(alpha+X_censored * beta)); //log-likelihood for censored times
}

generated quantities{
  vector[N_uncensored] times_uncensored_sampled; //prediction of death
  for(i in 1:N_uncensored) {
    times_uncensored_sampled[i] = exponential_rng(exp(alpha+X_uncensored[i,]* beta));
  }
}
"
# prepare the data
set.seed(42); 
require (tidyverse);
data <- read_csv('../data.csv')
New names:
* `` -> ...1
Rows: 2066 Columns: 12
── Column specification ───────────────────────────────────────────────────────────────────────────────────────
Delimiter: ","
chr (3): url, host_type, project
dbl (8): ...1, major_releases, duration, author_count, rev_count, status, multi_repo, commits_per_day
lgl (1): commit_freq_above_median

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
N <- nrow (data); 
X <- as.matrix(pull(data, major_releases)); 
is_censored <- pull(data, status)==0; 
times <- pull(data, duration); 
msk_censored <- is_censored == 1; 
N_censored <- sum(msk_censored);
Stan_data <- list (N_uncensored = N - N_censored, 
                    N_censored = N_censored,
                    numCovariates = ncol(X), 
                    X_censored = as.matrix(X[msk_censored,]),
                    X_uncensored = as.matrix(X[!msk_censored ,]), 
                    times_censored = times[msk_censored],
                    times_uncensored = times[!msk_censored])
# Fit Stan model
require(rstan)
exp_surv_model_fit <- suppressMessages(stan(model_code = Stan_exponential_survival_model, data = Stan_data))
Warning in system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :
  error in running command
clang: error: no input files

SAMPLING FOR MODEL 'bf5dbbde6a245330de71a285e3fe7c42' NOW (CHAIN 1).
Chain 1: 
Chain 1: Gradient evaluation took 0.000364 seconds
Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 3.64 seconds.
Chain 1: Adjust your expectations accordingly!
Chain 1: 
Chain 1: 
Chain 1: Iteration:    1 / 2000 [  0%]  (Warmup)
Chain 1: Iteration:  200 / 2000 [ 10%]  (Warmup)
Chain 1: Iteration:  400 / 2000 [ 20%]  (Warmup)
Chain 1: Iteration:  600 / 2000 [ 30%]  (Warmup)
Chain 1: Iteration:  800 / 2000 [ 40%]  (Warmup)
Chain 1: Iteration: 1000 / 2000 [ 50%]  (Warmup)
Chain 1: Iteration: 1001 / 2000 [ 50%]  (Sampling)
Chain 1: Iteration: 1200 / 2000 [ 60%]  (Sampling)
Chain 1: Iteration: 1400 / 2000 [ 70%]  (Sampling)
Chain 1: Iteration: 1600 / 2000 [ 80%]  (Sampling)
Chain 1: Iteration: 1800 / 2000 [ 90%]  (Sampling)
Chain 1: Iteration: 2000 / 2000 [100%]  (Sampling)
Chain 1: 
Chain 1:  Elapsed Time: 1.04487 seconds (Warm-up)
Chain 1:                0.941805 seconds (Sampling)
Chain 1:                1.98667 seconds (Total)
Chain 1: 

SAMPLING FOR MODEL 'bf5dbbde6a245330de71a285e3fe7c42' NOW (CHAIN 2).
Chain 2: 
Chain 2: Gradient evaluation took 0.000168 seconds
Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 1.68 seconds.
Chain 2: Adjust your expectations accordingly!
Chain 2: 
Chain 2: 
Chain 2: Iteration:    1 / 2000 [  0%]  (Warmup)
Chain 2: Iteration:  200 / 2000 [ 10%]  (Warmup)
Chain 2: Iteration:  400 / 2000 [ 20%]  (Warmup)
Chain 2: Iteration:  600 / 2000 [ 30%]  (Warmup)
Chain 2: Iteration:  800 / 2000 [ 40%]  (Warmup)
Chain 2: Iteration: 1000 / 2000 [ 50%]  (Warmup)
Chain 2: Iteration: 1001 / 2000 [ 50%]  (Sampling)
Chain 2: Iteration: 1200 / 2000 [ 60%]  (Sampling)
Chain 2: Iteration: 1400 / 2000 [ 70%]  (Sampling)
Chain 2: Iteration: 1600 / 2000 [ 80%]  (Sampling)
Chain 2: Iteration: 1800 / 2000 [ 90%]  (Sampling)
Chain 2: Iteration: 2000 / 2000 [100%]  (Sampling)
Chain 2: 
Chain 2:  Elapsed Time: 0.994872 seconds (Warm-up)
Chain 2:                0.916381 seconds (Sampling)
Chain 2:                1.91125 seconds (Total)
Chain 2: 

SAMPLING FOR MODEL 'bf5dbbde6a245330de71a285e3fe7c42' NOW (CHAIN 3).
Chain 3: 
Chain 3: Gradient evaluation took 0.00017 seconds
Chain 3: 1000 transitions using 10 leapfrog steps per transition would take 1.7 seconds.
Chain 3: Adjust your expectations accordingly!
Chain 3: 
Chain 3: 
Chain 3: Iteration:    1 / 2000 [  0%]  (Warmup)
Chain 3: Iteration:  200 / 2000 [ 10%]  (Warmup)
Chain 3: Iteration:  400 / 2000 [ 20%]  (Warmup)
Chain 3: Iteration:  600 / 2000 [ 30%]  (Warmup)
Chain 3: Iteration:  800 / 2000 [ 40%]  (Warmup)
Chain 3: Iteration: 1000 / 2000 [ 50%]  (Warmup)
Chain 3: Iteration: 1001 / 2000 [ 50%]  (Sampling)
Chain 3: Iteration: 1200 / 2000 [ 60%]  (Sampling)
Chain 3: Iteration: 1400 / 2000 [ 70%]  (Sampling)
Chain 3: Iteration: 1600 / 2000 [ 80%]  (Sampling)
Chain 3: Iteration: 1800 / 2000 [ 90%]  (Sampling)
Chain 3: Iteration: 2000 / 2000 [100%]  (Sampling)
Chain 3: 
Chain 3:  Elapsed Time: 1.01847 seconds (Warm-up)
Chain 3:                0.976654 seconds (Sampling)
Chain 3:                1.99513 seconds (Total)
Chain 3: 

SAMPLING FOR MODEL 'bf5dbbde6a245330de71a285e3fe7c42' NOW (CHAIN 4).
Chain 4: 
Chain 4: Gradient evaluation took 0.000176 seconds
Chain 4: 1000 transitions using 10 leapfrog steps per transition would take 1.76 seconds.
Chain 4: Adjust your expectations accordingly!
Chain 4: 
Chain 4: 
Chain 4: Iteration:    1 / 2000 [  0%]  (Warmup)
Chain 4: Iteration:  200 / 2000 [ 10%]  (Warmup)
Chain 4: Iteration:  400 / 2000 [ 20%]  (Warmup)
Chain 4: Iteration:  600 / 2000 [ 30%]  (Warmup)
Chain 4: Iteration:  800 / 2000 [ 40%]  (Warmup)
Chain 4: Iteration: 1000 / 2000 [ 50%]  (Warmup)
Chain 4: Iteration: 1001 / 2000 [ 50%]  (Sampling)
Chain 4: Iteration: 1200 / 2000 [ 60%]  (Sampling)
Chain 4: Iteration: 1400 / 2000 [ 70%]  (Sampling)
Chain 4: Iteration: 1600 / 2000 [ 80%]  (Sampling)
Chain 4: Iteration: 1800 / 2000 [ 90%]  (Sampling)
Chain 4: Iteration: 2000 / 2000 [100%]  (Sampling)
Chain 4: 
Chain 4:  Elapsed Time: 1.03277 seconds (Warm-up)
Chain 4:                0.782076 seconds (Sampling)
Chain 4:                1.81484 seconds (Total)
Chain 4: 
print(get_seed(exp_surv_model_fit))
[1] 1781592037
fit_summary <- summary(exp_surv_model_fit)
print(fit_summary$summary)
                                      mean      se_mean           sd         2.5%          25%          50%
beta[1]                          -1.443823 7.741168e-03   0.37556309    -2.269815    -1.672497    -1.416993
alpha                            -4.970648 7.041629e-04   0.03949185    -5.047143    -4.997410    -4.970395
times_uncensored_sampled[1]     144.282825 2.270819e+00 143.99604902     3.533011    42.631682    99.013253
times_uncensored_sampled[2]     142.049451 2.220240e+00 143.98011185     3.597634    41.297460    97.909677
times_uncensored_sampled[3]     143.681743 2.383723e+00 146.90173593     3.526873    40.166865   100.249813
times_uncensored_sampled[4]     147.940028 2.396533e+00 147.47844884     3.492281    42.198498   103.913578
times_uncensored_sampled[5]     144.072585 2.268754e+00 142.20799642     3.332208    42.567151   101.855460
times_uncensored_sampled[6]     141.459204 2.194185e+00 137.25167113     3.942252    41.348813   100.434474
times_uncensored_sampled[7]     146.396309 2.412435e+00 145.28463176     3.203863    42.866143   102.307336
times_uncensored_sampled[8]     143.001219 2.362735e+00 143.74343483     3.455600    40.665804    98.635272
times_uncensored_sampled[9]     144.335856 2.336259e+00 144.63102811     4.088224    40.547548   101.096353
times_uncensored_sampled[10]    147.111391 2.286544e+00 142.35902506     3.709886    44.315421   105.105785
times_uncensored_sampled[11]    146.528762 2.363002e+00 148.16365871     3.725527    42.723460   100.205743
times_uncensored_sampled[12]    149.020031 2.422250e+00 150.56216963     3.737042    42.857007    98.798149
times_uncensored_sampled[13]    145.815055 2.383654e+00 146.41888316     3.677345    39.886758    99.083650
times_uncensored_sampled[14]    142.019563 2.337650e+00 142.15558681     4.151210    39.360568    98.069704
times_uncensored_sampled[15]    143.633097 2.288964e+00 142.58768532     3.598670    42.670476   101.354741
times_uncensored_sampled[16]    143.417157 2.299210e+00 143.89888142     3.481819    40.343629    97.948237
times_uncensored_sampled[17]    144.698390 2.346819e+00 143.66384196     3.647003    41.019738   100.720369
times_uncensored_sampled[18]    140.608868 2.199956e+00 138.92005397     3.562913    40.184634    97.612878
times_uncensored_sampled[19]    145.051090 2.243761e+00 144.43637949     3.717424    41.390752   101.134265
times_uncensored_sampled[20]    148.814756 2.355899e+00 151.99359589     3.953208    41.570997    99.035485
times_uncensored_sampled[21]    145.313685 2.284689e+00 145.70851375     3.829402    43.233746   100.003299
times_uncensored_sampled[22]    144.549037 2.336422e+00 146.36846367     3.965298    40.002182    99.853245
times_uncensored_sampled[23]    147.466604 2.464049e+00 147.67448089     4.102182    43.701342   102.171753
times_uncensored_sampled[24]    147.509289 2.377058e+00 145.29530336     3.492302    44.142380   104.052366
times_uncensored_sampled[25]    142.016985 2.251500e+00 141.98864983     3.443717    39.591148    99.511185
times_uncensored_sampled[26]    143.192410 2.405582e+00 146.69653396     3.317775    40.124828    97.275403
times_uncensored_sampled[27]    137.770359 2.244729e+00 136.94499608     3.353410    39.308582    96.910231
times_uncensored_sampled[28]    143.282016 2.346454e+00 145.38638336     3.235814    41.368855    98.529101
times_uncensored_sampled[29]    143.871788 2.207890e+00 141.47101074     3.958167    42.941207   100.618405
times_uncensored_sampled[30]    145.088572 2.306396e+00 144.16620829     3.645319    42.610046   100.907433
times_uncensored_sampled[31]    142.719657 2.278574e+00 141.94586922     3.546179    41.476992    98.184856
times_uncensored_sampled[32]    140.051218 2.295105e+00 142.74993721     3.105984    39.326593    97.556878
times_uncensored_sampled[33]    142.178784 2.241846e+00 141.88055847     3.524278    40.505072    98.679621
times_uncensored_sampled[34]    145.801554 2.563088e+00 149.42124690     3.900367    40.689796    98.392061
times_uncensored_sampled[35]    145.879516 2.461091e+00 151.98857263     4.153748    41.403585    96.513313
times_uncensored_sampled[36]    143.234231 2.189528e+00 141.52480259     3.820332    41.667923   100.437659
times_uncensored_sampled[37]    139.812675 2.185740e+00 138.18667422     3.800950    41.075163    99.072104
times_uncensored_sampled[38]    143.519709 2.251572e+00 142.31646615     3.370824    41.964358    99.626226
times_uncensored_sampled[39]    142.793868 2.209649e+00 142.50019214     3.550388    41.012410    99.562957
times_uncensored_sampled[40]    141.461805 2.093582e+00 137.38391008     3.219756    41.864017    99.293080
times_uncensored_sampled[41]    144.460123 2.358926e+00 146.51556372     3.070663    42.282216   100.182875
times_uncensored_sampled[42]    145.339032 2.384344e+00 148.09500993     4.057736    41.668664    99.859916
times_uncensored_sampled[43]    144.334921 2.271561e+00 144.51700401     3.834080    41.881430    98.090594
times_uncensored_sampled[44]    146.912315 2.316457e+00 146.12111889     3.642973    41.976632   103.653147
times_uncensored_sampled[45]    141.234360 2.344186e+00 149.64304347     3.549195    38.941196    92.620201
times_uncensored_sampled[46]    143.568146 2.279709e+00 142.20697405     3.361309    40.571079   100.146449
times_uncensored_sampled[47]    144.007247 2.375325e+00 147.81373606     3.607610    39.311587    97.790493
times_uncensored_sampled[48]    141.510123 2.201146e+00 139.40529419     3.474515    41.202829    99.791470
times_uncensored_sampled[49]    146.138800 2.283095e+00 143.84853969     4.291024    42.880568   103.320078
times_uncensored_sampled[50]    140.079121 2.272051e+00 140.25151437     3.842098    41.188755    98.090586
times_uncensored_sampled[51]    147.864411 2.265270e+00 145.31773698     3.737743    44.825054   105.665093
times_uncensored_sampled[52]    146.769312 2.283992e+00 148.76796121     3.490648    41.283047   101.274938
times_uncensored_sampled[53]    140.558807 2.214036e+00 138.14543168     3.479361    41.490388    96.802662
times_uncensored_sampled[54]    144.362216 2.310476e+00 144.70660063     3.072260    41.330708   101.929344
times_uncensored_sampled[55]    144.815780 2.213933e+00 142.00418059     3.400743    41.817152   101.986213
times_uncensored_sampled[56]    147.224520 2.369569e+00 146.92160235     4.190908    43.059524   100.010094
times_uncensored_sampled[57]    148.516835 2.323984e+00 146.25981884     3.731607    43.007980   103.425354
times_uncensored_sampled[58]    147.466188 2.451235e+00 147.87267394     3.530621    43.704700   102.408963
times_uncensored_sampled[59]    146.247150 2.313343e+00 147.94423654     3.197958    40.800675   101.702331
times_uncensored_sampled[60]    142.646919 2.297262e+00 145.38660204     3.261655    39.406142    95.822694
times_uncensored_sampled[61]    146.779142 2.296909e+00 146.27532389     3.933223    41.826343   103.336411
times_uncensored_sampled[62]    143.865616 2.294611e+00 147.48811713     3.283372    41.817799    98.563118
times_uncensored_sampled[63]    141.087128 2.172258e+00 139.59805299     3.836860    38.759920    97.339037
times_uncensored_sampled[64]    144.561457 2.192162e+00 140.86793225     3.674060    42.193995   101.191939
times_uncensored_sampled[65]    144.635486 2.289666e+00 144.99386442     4.172843    42.425001   100.578781
times_uncensored_sampled[66]    142.415027 2.437683e+00 142.96499775     3.872056    40.157561    99.144183
times_uncensored_sampled[67]    144.412029 2.364486e+00 143.24145100     3.681522    41.937484   101.514677
times_uncensored_sampled[68]    144.967681 2.267685e+00 144.54250402     4.094467    42.628584   101.112635
times_uncensored_sampled[69]    145.616214 2.519803e+00 144.98110354     3.215748    40.478936   101.107535
times_uncensored_sampled[70]    146.645674 2.388842e+00 149.60568024     3.801788    41.042622   102.145912
times_uncensored_sampled[71]    144.190706 2.294334e+00 143.78476233     3.973352    39.145691   101.707035
times_uncensored_sampled[72]    142.191461 2.305302e+00 145.56731944     3.390068    40.842779    99.812088
times_uncensored_sampled[73]    146.830930 2.385948e+00 147.78177159     3.634404    42.174273   102.950814
times_uncensored_sampled[74]    144.711202 2.296045e+00 144.48118225     3.464418    41.661525   100.112510
times_uncensored_sampled[75]    141.488622 2.275692e+00 142.74792714     3.071740    38.889373    97.288471
times_uncensored_sampled[76]    143.737942 2.178045e+00 141.85460915     3.661001    40.267977    99.449284
times_uncensored_sampled[77]    141.660350 2.234000e+00 142.16055973     3.683461    41.261742    98.259845
times_uncensored_sampled[78]    145.273100 2.285990e+00 145.01152850     3.627593    39.426782   101.818732
times_uncensored_sampled[79]    144.631878 2.283563e+00 142.39709377     4.124197    42.561125   100.398470
times_uncensored_sampled[80]    143.185064 2.274880e+00 144.44978717     3.573561    40.957688    95.756127
times_uncensored_sampled[81]    145.929450 2.336856e+00 144.45918192     3.697612    43.992742   101.233657
times_uncensored_sampled[82]    140.796271 2.265435e+00 142.72116239     3.419260    39.523381    96.752140
times_uncensored_sampled[83]    143.292165 2.331730e+00 142.15072246     3.798934    41.726672   100.615830
times_uncensored_sampled[84]    150.168783 2.405436e+00 151.46796863     3.610563    43.065026   104.435474
times_uncensored_sampled[85]    143.566344 2.263366e+00 141.23126396     3.862335    43.515781    99.941240
times_uncensored_sampled[86]    144.978007 2.335859e+00 144.32398450     3.408278    41.127800   102.151164
times_uncensored_sampled[87]    146.398257 2.500830e+00 148.93100064     3.960118    41.845157   102.567995
times_uncensored_sampled[88]    147.143777 2.322813e+00 144.75664380     3.505223    43.281681   102.794827
times_uncensored_sampled[89]    144.509862 2.236111e+00 144.58513816     4.019491    42.626250   102.044526
times_uncensored_sampled[90]    142.455910 2.251183e+00 143.07305973     3.417098    39.420329    97.959825
times_uncensored_sampled[91]    145.289441 2.308068e+00 146.91408872     3.736474    42.365050   101.142873
times_uncensored_sampled[92]    142.695959 2.280783e+00 146.87379569     3.277844    41.179659    97.240406
times_uncensored_sampled[93]    145.994066 2.261820e+00 144.92316249     3.521301    44.376710   101.634127
times_uncensored_sampled[94]    143.338370 2.303467e+00 141.45327527     3.828928    41.261654    97.772096
times_uncensored_sampled[95]    145.322512 2.309336e+00 144.81735272     3.985905    42.595606   100.219408
times_uncensored_sampled[96]    143.196775 2.352259e+00 146.88606791     3.872517    40.776259    95.406520
times_uncensored_sampled[97]    142.195894 2.190794e+00 140.17784445     3.617841    41.471628    99.615128
times_uncensored_sampled[98]    143.412946 2.333277e+00 145.02137030     3.655814    38.717505    98.536042
                                       75%         97.5%    n_eff      Rhat
beta[1]                          -1.184759    -0.7710732 2353.709 1.0005282
alpha                            -4.942197    -4.8952610 3145.349 0.9999338
times_uncensored_sampled[1]     203.273879   529.3350838 4021.019 1.0006641
times_uncensored_sampled[2]     192.397401   543.2946941 4205.380 0.9996345
times_uncensored_sampled[3]     196.431606   537.7358525 3797.888 0.9995316
times_uncensored_sampled[4]     206.750579   552.5698700 3786.956 0.9996655
times_uncensored_sampled[5]     198.249420   526.9757562 3928.920 1.0009630
times_uncensored_sampled[6]     197.987098   521.7031163 3912.809 0.9997256
times_uncensored_sampled[7]     201.750808   540.6731195 3626.838 1.0008689
times_uncensored_sampled[8]     200.704310   523.1983841 3701.229 0.9994011
times_uncensored_sampled[9]     202.000052   527.3956789 3832.489 0.9995421
times_uncensored_sampled[10]    203.571507   515.2868368 3876.243 0.9994476
times_uncensored_sampled[11]    200.928320   550.9088984 3931.473 0.9991638
times_uncensored_sampled[12]    206.457949   549.6471889 3863.614 1.0010614
times_uncensored_sampled[13]    204.013470   541.8197924 3773.183 1.0014249
times_uncensored_sampled[14]    194.369170   517.9371979 3698.018 1.0007314
times_uncensored_sampled[15]    200.408142   521.9892510 3880.487 1.0002020
times_uncensored_sampled[16]    197.727118   528.0525905 3917.036 0.9996031
times_uncensored_sampled[17]    202.088063   534.5643330 3747.449 1.0009426
times_uncensored_sampled[18]    193.968199   534.1569944 3987.511 0.9997016
times_uncensored_sampled[19]    200.200959   541.0848538 4143.813 0.9995590
times_uncensored_sampled[20]    206.525047   558.2741244 4162.338 0.9999818
times_uncensored_sampled[21]    198.377063   553.6842429 4067.388 0.9998197
times_uncensored_sampled[22]    198.863991   523.2290036 3924.575 0.9995257
times_uncensored_sampled[23]    204.413866   549.0375743 3591.800 0.9997577
times_uncensored_sampled[24]    202.981878   546.3531349 3736.145 1.0003559
times_uncensored_sampled[25]    200.057031   514.6716842 3977.073 1.0003631
times_uncensored_sampled[26]    196.504778   536.8116119 3718.770 1.0003746
times_uncensored_sampled[27]    190.970343   519.4883820 3721.897 0.9996333
times_uncensored_sampled[28]    195.206522   546.6138806 3839.046 1.0006058
times_uncensored_sampled[29]    198.960349   523.6339778 4105.634 0.9997565
times_uncensored_sampled[30]    202.335776   540.1239303 3907.141 1.0005862
times_uncensored_sampled[31]    195.785339   506.8563190 3880.784 0.9990611
times_uncensored_sampled[32]    193.518278   523.8499276 3868.536 0.9994216
times_uncensored_sampled[33]    195.564715   525.5384020 4005.292 1.0010819
times_uncensored_sampled[34]    201.770879   544.6281098 3398.581 1.0005868
times_uncensored_sampled[35]    198.352793   552.8106796 3813.875 0.9998591
times_uncensored_sampled[36]    196.991616   530.6394844 4177.957 0.9993079
times_uncensored_sampled[37]    192.642138   506.5656760 3997.010 0.9999563
times_uncensored_sampled[38]    198.298359   516.5395471 3995.201 0.9995522
times_uncensored_sampled[39]    198.406125   533.7245553 4158.956 0.9999016
times_uncensored_sampled[40]    199.010637   516.9831836 4306.178 0.9995443
times_uncensored_sampled[41]    199.476944   533.9606553 3857.794 1.0005261
times_uncensored_sampled[42]    197.044421   550.0275779 3857.829 0.9999901
times_uncensored_sampled[43]    199.463220   530.0697749 4047.522 1.0004064
times_uncensored_sampled[44]    209.308219   536.8236734 3979.031 0.9997137
times_uncensored_sampled[45]    190.181393   547.9942485 4075.011 0.9993920
times_uncensored_sampled[46]    202.180964   512.9227377 3891.195 0.9995927
times_uncensored_sampled[47]    199.544368   533.1165892 3872.430 0.9999772
times_uncensored_sampled[48]    197.674842   504.9013273 4011.076 1.0004068
times_uncensored_sampled[49]    204.014614   518.0433868 3969.748 1.0002660
times_uncensored_sampled[50]    192.344902   527.0716821 3810.475 1.0004348
times_uncensored_sampled[51]    203.015844   551.6811206 4115.261 0.9997718
times_uncensored_sampled[52]    200.365212   542.0418143 4242.577 1.0002386
times_uncensored_sampled[53]    194.785500   521.4662889 3893.173 0.9995966
times_uncensored_sampled[54]    201.363129   518.7394479 3922.598 0.9993780
times_uncensored_sampled[55]    203.606903   517.2742484 4114.087 0.9992433
times_uncensored_sampled[56]    203.092805   548.3881803 3844.434 0.9992525
times_uncensored_sampled[57]    208.681660   537.2593257 3960.809 0.9998864
times_uncensored_sampled[58]    202.774602   561.4514679 3639.199 1.0004360
times_uncensored_sampled[59]    199.461391   548.2524395 4089.931 1.0004229
times_uncensored_sampled[60]    197.347913   532.7997217 4005.232 0.9995835
times_uncensored_sampled[61]    202.227467   543.1142693 4055.594 0.9998767
times_uncensored_sampled[62]    197.135531   530.0838017 4131.387 0.9999286
times_uncensored_sampled[63]    197.520810   511.1941401 4129.864 0.9994763
times_uncensored_sampled[64]    201.868626   524.2925318 4129.324 0.9994295
times_uncensored_sampled[65]    196.064663   529.4288402 4010.100 1.0005010
times_uncensored_sampled[66]    196.847267   520.6327709 3439.576 0.9995612
times_uncensored_sampled[67]    197.754368   530.2855270 3669.983 1.0004197
times_uncensored_sampled[68]    203.030846   534.0481583 4062.804 0.9995391
times_uncensored_sampled[69]    204.626780   534.8426058 3310.469 1.0005905
times_uncensored_sampled[70]    199.073409   556.0940983 3922.124 0.9999916
times_uncensored_sampled[71]    203.898841   524.6755715 3927.466 1.0012705
times_uncensored_sampled[72]    196.092198   519.6076121 3987.237 1.0001658
times_uncensored_sampled[73]    204.303270   542.3965371 3836.362 0.9999543
times_uncensored_sampled[74]    201.591826   541.0279393 3959.697 1.0000814
times_uncensored_sampled[75]    195.722819   524.7481510 3934.709 1.0001302
times_uncensored_sampled[76]    201.079497   509.0865133 4241.829 0.9997263
times_uncensored_sampled[77]    193.980598   531.0454820 4049.411 0.9997303
times_uncensored_sampled[78]    204.266895   531.5536853 4023.986 1.0007362
times_uncensored_sampled[79]    203.086613   528.0050740 3888.447 0.9998760
times_uncensored_sampled[80]    198.710197   544.2139274 4031.964 0.9996293
times_uncensored_sampled[81]    203.379213   537.7619275 3821.435 0.9993326
times_uncensored_sampled[82]    195.753268   529.2473350 3968.931 1.0000777
times_uncensored_sampled[83]    196.717166   535.5867097 3716.564 1.0004427
times_uncensored_sampled[84]    209.715471   555.9776134 3965.099 1.0001464
times_uncensored_sampled[85]    200.005397   507.2338442 3893.606 1.0006397
times_uncensored_sampled[86]    201.451121   536.3697813 3817.541 0.9998703
times_uncensored_sampled[87]    197.126275   554.9081798 3546.515 1.0015126
times_uncensored_sampled[88]    203.790693   549.4351180 3883.727 0.9998204
times_uncensored_sampled[89]    198.953402   536.9199643 4180.812 1.0005915
times_uncensored_sampled[90]    198.796912   513.2883391 4039.188 1.0000612
times_uncensored_sampled[91]    201.972885   535.4546581 4051.628 1.0001434
times_uncensored_sampled[92]    195.570060   539.2370172 4146.871 0.9998138
times_uncensored_sampled[93]    203.702991   529.9039039 4105.437 0.9998317
times_uncensored_sampled[94]    201.636581   525.7576150 3771.046 1.0000440
times_uncensored_sampled[95]    202.099370   522.7787019 3932.484 1.0001446
times_uncensored_sampled[96]    196.872349   539.6454847 3899.340 0.9996693
times_uncensored_sampled[97]    193.406199   533.3815402 4094.074 1.0001751
times_uncensored_sampled[98]    195.913475   539.4857586 3863.058 1.0004989
 [ reached getOption("max.print") -- omitted 547 rows ]
exp_surv_model_draws <- tidybayes::tidy_draws(exp_surv_model_fit)
exp_surv_model_draws
## Constructor for Strata-specific survival function
construct_survival_function <- function(alpha, beta, x) {
    function(t) {
        lambda <- exp(alpha + x*beta)
        exp(-(lambda * t))
    }
}

## Random functions
exp_surv_model_surv_func <-
    exp_surv_model_draws %>%
    select(.chain, .iteration, .draw, alpha, `beta[1]`) %>%
    ## Simplify name
    rename(beta = `beta[1]`) %>%
    ## Construct realization of random functions
    mutate(`S(t|1)` = pmap(list(alpha, beta), function(a,b) {construct_survival_function(a,b,1)}),
           `S(t|0)` = pmap(list(alpha, beta), function(a,b) {construct_survival_function(a,b,0)}))
exp_surv_model_surv_func
times <- seq(from = 0, to = 165, by = 0.1)
times_df <- data_frame(t = times)

## Try first realizations
exp_surv_model_surv_func$`S(t|1)`[[1]](times[1:10])
 [1] 1.0000000 0.9998471 0.9996941 0.9995412 0.9993883 0.9992355 0.9990827 0.9989298 0.9987771 0.9986243
exp_surv_model_surv_func$`S(t|0)`[[1]](times[1:10])
 [1] 1.0000000 0.9992607 0.9985220 0.9977839 0.9970463 0.9963092 0.9955727 0.9948367 0.9941012 0.9933663
## Apply all realizations
exp_surv_model_survival <-
    exp_surv_model_surv_func %>%
    mutate(times_df = list(times_df)) %>%
    mutate(times_df = pmap(list(times_df, `S(t|1)`, `S(t|0)`),
                           function(df, s1, s0) {df %>% mutate(s1 = s1(t),
                                                               s0 = s0(t))})) %>%
    select(-`S(t|1)`, -`S(t|0)`) %>%
    unnest(cols = c(times_df)) %>%
    gather(key = Strata, value = survival, s1, s0) %>%
    mutate(Strata = factor(Strata, # Strata is whether or not project has major releases
                              levels = c("s1","s0"),
                              labels = c("major releases=Yes","major releases=No")))

## Average on survival scale
exp_surv_model_survival_mean <-
    exp_surv_model_survival %>%
    group_by(Strata, t) %>%
    summarize(survival_mean = mean(survival),
              survival_95upper = quantile(survival, probs = 0.975),
              survival_95lower = quantile(survival, probs = 0.025))
`summarise()` has grouped output by 'Strata'. You can override using the `.groups` argument.
exp_surv_model_survival
(ggplot(data = exp_surv_model_survival, mapping = aes(x = t, y = survival, color = Strata, group = interaction(.chain,.draw,Strata))) 
 + geom_line(size = 0.1, alpha = 0.02) 
 + geom_line(data = exp_surv_model_survival_mean, mapping = aes(y = survival_mean, group = Strata)) 
 + geom_line(data = exp_surv_model_survival_mean, mapping = aes(y = survival_95upper, group = Strata), linetype = "dotted") 
 + geom_line(data = exp_surv_model_survival_mean, mapping = aes(y = survival_95lower, group = Strata), linetype = "dotted")
 + scale_color_hue(direction = -1)
 + theme_bw()
 + theme(axis.text.x = element_text(angle = 90, vjust = 0.5), legend.key = element_blank(), plot.title = element_text(hjust = 0.5), strip.background = element_blank()))

LS0tCnRpdGxlOiAiQmF5ZXNpYW4gc3Vydml2YWwgYW5hbHlzaXMgdXNpbmcgbWFqb3IgcmVsZWFzZXMgYXMgYSBwcmVkaWN0b3IiCm91dHB1dDogaHRtbF9ub3RlYm9vawotLS0KYGBge3J9CmxpYnJhcnkocnN0YW4pCmxpYnJhcnkoc3Vydml2YWwpCmxpYnJhcnkodGlkeXZlcnNlKQpsaWJyYXJ5KHRpZHliYXllcykKYGBgCiAKCmBgYHtyfQpTdGFuX2V4cG9uZW50aWFsX3N1cnZpdmFsX21vZGVsIDwtICIKZGF0YXsKICBpbnQgPGxvd2VyPTE+IE5fdW5jZW5zb3JlZDsKICBpbnQgPGxvd2VyPTE+IE5fY2Vuc29yZWQ7CiAgaW50IDxsb3dlcj0wPiBudW1Db3ZhcmlhdGVzOwogIG1hdHJpeFtOX2NlbnNvcmVkLCBudW1Db3ZhcmlhdGVzXSBYX2NlbnNvcmVkOwogIG1hdHJpeFtOX3VuY2Vuc29yZWQsIG51bUNvdmFyaWF0ZXNdIFhfdW5jZW5zb3JlZDsKICB2ZWN0b3IgPGxvd2VyPTA+W05fY2Vuc29yZWRdIHRpbWVzX2NlbnNvcmVkOwogIHZlY3RvciA8bG93ZXI9MD5bTl91bmNlbnNvcmVkXSB0aW1lc191bmNlbnNvcmVkOwp9CgpwYXJhbWV0ZXJzewogIHZlY3RvcltudW1Db3ZhcmlhdGVzXSBiZXRhOyAvL3JlZ3Jlc3Npb24gY29lZm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